package com.atguigu.utils

import java.sql.Connection
import java.util.Properties

import com.alibaba.druid.pool.DruidDataSourceFactory

/**
 * JDBC c3p0连接池工具
 *
 * @author WangJX
 * @date 2019/11/29 18:16 
 * @version 1.0
 */
object JDBCUtils {

  private var conn: Connection = null

  private def connDruid = {
    val proper = new Properties()
    proper.load(JDBCUtils.getClass.getClassLoader().getResourceAsStream("druid.properties"))
    val dataSource = DruidDataSourceFactory.createDataSource(proper)
    conn = dataSource.getConnection()
  }

  //获取Druid连接
  def getConnection  ={
    if (conn == null) {
      connDruid
    }
    conn
  }

  def main(args: Array[String]): Unit = {
    val conn = getConnection
    println(conn)
  }
}
